package 尚硅谷juc大厂.test3;

import java.util.concurrent.*;

public class Test3 {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CompletableFuture<Integer> future = CompletableFuture.supplyAsync(() -> {
            try {
                TimeUnit.SECONDS.sleep(2);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return 1;
        //thenApply依赖上一个异步
        }).thenApply(f->{
            return f+1;
            //whenComplete线程执行完毕，执行回调方法
        }).whenComplete((v,e)->{
            if (e==null){
                System.out.println("结果为："+v);
            }
            //线程异常，执行回调方法
        }).exceptionally(e->{
            e.printStackTrace();
            return null;
        });


    }
}
